package com.aote.model.block;

import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.htmlcomponent.HTMLTableModel;
import com.browsesoft.parameter.Parameter;
import com.browsesoft.parameter.ParameterValue;

/**
 * 系统参数块模型 所提供的数据为系统参数，在该模型所在元素配置参数 paramname="参数名"
 */
public class SysParamBlockModel implements HTMLTableModel {

	/**
	 * 组件
	 */
	protected HTMLBasicComponent component = null;

	/**
	 * 数据，List的每一项为参数值对象
	 */
	protected List datas = new LinkedList();

	public void init(HttpServletRequest request) throws Exception {

	}

	public void setComponent(HTMLBasicComponent component) {
		this.component = component;
	}

	public int getColumnCount() {
		return this.datas.size();
	}

	public String getColumnName(int index) {
		ParameterValue pv = (ParameterValue) this.datas.get(index);
		return pv.getName();
	}

	public int getRowCount() {
		return 0;
	}

	public void setCondition(String condition) {
	}

	public void modifyCellValue(Element td, Document doc, int row, int col) {
	}

	public String getType(int col) {
		return null;
	}

	public void updatePageElement(HTMLBasicComponent c) throws Exception {
	}

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 得到配置的参数名称，得到参数值，参数值即为数据
		String paramName = this.component.getElement()
				.getAttribute("paramname");
		Parameter p = new Parameter(paramName);
		this.datas = p.getParamValues();
	}

}
